package com.huawei.appmarket.service.store.awk.card;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout.LayoutParams;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.MultiLineLabelLayout;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailLabelBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailLabelBean.DetailLabel;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.List;
import o.azb;
import o.cgz;
import o.cjk;
import o.cjm;
import o.cjo;
import o.ckt;
import o.djc;
import o.Logger;
import o.ContentManager;
import o.ewm.d;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class DetailLabelGeneralCard extends BaseDistCard implements OnClickListener {
    private DetailLabelBean ʻ;
    private LayoutInflater ˋ;
    private MultiLineLabelLayout ॱॱ;
    private TextView ᐝ;

    public /* synthetic */ cgz ˏ(View view) {
        return ˎ(view);
    }

    public DetailLabelGeneralCard(Context context) {
        super(context);
    }

    public DetailLabelGeneralCard ˎ(View view) {
        azb.ˏ(view, j.ʾꜟ);
        this.ॱॱ = (MultiLineLabelLayout) view.findViewById(j.ॱﹺ);
        azb.ˋ(this.ॱॱ);
        this.ᐝ = (TextView) view.findViewById(j.ʼﾞ);
        this.ᐝ.setText(ContentManager.getInstant().getContext().getResources().getString(n.ㆍॱ));
        this.ॱॱ.ˏ = (int) ContentManager.getInstant().getContext().getResources().getDimension(d.ˎˎ);
        ʽ(view);
        this.ˋ = LayoutInflater.from(this.ʼॱ);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        this.ʻ = (DetailLabelBean) cardBean;
        if (this.ʻ != null && this.ʻ.ॱ() != null && this.ʻ.ॱ().size() > 0) {
            int size = this.ʻ.ॱ().size();
            int defaultColor = this.ᐝ.getTextColors().getDefaultColor();
            for (int i = 0; i < size; i++) {
                ToggleButton toggleButton;
                if (i > this.ॱॱ.getChildCount() - 1) {
                    View inflate = this.ˋ.inflate(h.ˑ, null);
                    inflate.setLayoutParams(ॱ(inflate, i, size));
                    ToggleButton toggleButton2 = (ToggleButton) inflate.findViewById(j.ˈـ);
                    inflate.setTag(toggleButton2);
                    this.ॱॱ.addView(inflate);
                    toggleButton = toggleButton2;
                } else {
                    toggleButton = (ToggleButton) this.ॱॱ.getChildAt(i).getTag();
                }
                toggleButton.setText(((DetailLabel) this.ʻ.ॱ().get(i)).ˊ());
                toggleButton.setTextOn(((DetailLabel) this.ʻ.ॱ().get(i)).ˊ());
                toggleButton.setTextOff(((DetailLabel) this.ʻ.ॱ().get(i)).ˊ());
                toggleButton.setId(j.ॱᵢ + i);
                toggleButton.setOnClickListener(new ckt(this));
                toggleButton.setTextColor(defaultColor);
            }
        }
    }

    public LayoutParams ॱ(View view, int i, int i2) {
        LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new LayoutParams(-2, -2);
        }
        layoutParams.bottomMargin = ContentManager.getInstant().getContext().getResources().getDimensionPixelSize(d.ॱˋ);
        return layoutParams;
    }

    public void onClick(View view) {
        int id = view.getId();
        int size = this.ʻ.ॱ().size();
        id -= j.ॱᵢ;
        if (id < 0 || id >= size) {
            Logger.e("DetailLabelCard", "list index out of bounds!");
            return;
        }
        DetailLabel detailLabel = (DetailLabel) this.ʻ.ॱ().get(id);
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        appDetailActivityProtocol.ˏ(new Request(detailLabel.ˎ(), detailLabel.ˏ()));
        cjm o_cjm = new cjm("appdetail.activity", appDetailActivityProtocol);
        Activity activity = (Activity) this.ʼॱ;
        try {
            List runningTasks = ((ActivityManager) ContentManager.getInstant().getContext().getSystemService("activity")).getRunningTasks(1);
            if (!(runningTasks == null || runningTasks.isEmpty())) {
                RunningTaskInfo runningTaskInfo = (RunningTaskInfo) runningTasks.get(0);
                if (runningTaskInfo != null && runningTaskInfo.numActivities > djc.ˋ() && runningTaskInfo.topActivity.getClassName().equals(activity.getClass().getName())) {
                    o_cjm.ॱ(activity).setFlags(HwAccountConstants.FLAG_TRANSLUCENT_STATUS);
                }
            }
        } catch (Throwable e) {
            Logger.ˋ("DetailLabelCard", "onClick error", e);
        }
        cjk.ˎ().ˋ(activity, o_cjm);
    }
}
